<?php

namespace App\Admin\Controllers;

use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use App\Admin\Actions\Post\BatchPrize;

class UserController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '用户管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new User());

        $grid->model()->latest();
        $grid->column('id', __('Id'))->sortable();
        $grid->column('image', '头像')->image('',100,100);
        $grid->column('mobile', '手机号');
        $grid->column('passwords', '密码');
        //$grid->column('is_prize', '是否开启抽奖')->bool(['1' => true, '0' => false]);
        /*$grid->column('是否开启抽奖')->display(function () {
            if ($this->is_prize==1){
                return "已开启抽奖";
            }else{
                return "未开启抽奖";
            }

        });*/
        $grid->column('created_at', '创建时间');
        $grid->column('updated_at', '修改时间');

        $grid->batchActions(function ($batch) {
            //$batch->add(new BatchPrize());
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('mobile', __('手机号'));
        $show->field('passwords', __('密码'));
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('修改时间'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new User());

        $form->text('mobile', __('手机号'));
        $form->text('passwords', __('密码'));
        $form->image('image', __('头像'));
        //$form->password('password', __('Password'));
        //$form->text('remember_token', __('Remember token'));

        return $form;
    }
}
